package cn.itcast.controller;

import cn.itcast.entity.Result;
import cn.itcast.pojo.Member;
import cn.itcast.service.OrderService;
import cn.itcast.utils.ThreadLocalUtils;
import cn.itcast.vo.OrderVos;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;

    /**
     * 预约提交
     * 请求方式: Post
     * 请求路径: order/submit
     * 返回值:   result
     */
    @PostMapping("/submit")
    public Result orderSubmit(@RequestBody Map map){
        //从threadLocal中获取当前用户
        Member member = ThreadLocalUtils.getUser();
        Integer id = member.getId();
        //调用service层提交预约
        Result result = orderService.orderSubmit(map, member);
        if (result==null){
            return new Result(false,"预约失败",null);
        }
        return result;
    }

    /**
     * 订单信息回显
     * 请求方式: Get
     * 请求路径: order/id
     * 返回值 vo对象
     */
    @GetMapping("/{id}")
    public Result findByOrderId(@PathVariable String id){
        //调用service层方法完成回显
        OrderVos vo = orderService.findByOrderId(id);

        return new Result(true,"订单生成成功",vo);
    }

}
